<template>
  <div class="app-container">
    <el-table v-loading="tableLoading" :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="applyDoctorName" label="提交医生"></el-table-column>
      <el-table-column prop="patientName" label="患者"></el-table-column>
      <el-table-column prop="changeDoctorName" label="更换医生"></el-table-column>
      <el-table-column prop="applyDate" label="申请时间"></el-table-column>
      <el-table-column label="原因">
        <template slot-scope="scope">
          <span :style="{ color: scope.row.state==1? 'rgb(3, 167, 240)' :scope.row.state==2 ? 'red':'' }">
            {{ scope.row.state==1? "审核通过" :scope.row.state==2 ?  "审核不通过":'待审核' }}</span>
          <div v-if="scope.row.state==2">{{scope.row.refuseReason}}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120px" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-popconfirm v-if="!scope.row.state" style="margin-left: 10px" title="确定通过吗？"
            @confirm="submit(scope.row,true)">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-check">通过
            </el-button>
          </el-popconfirm>
          <el-button v-if="!scope.row.state" size="mini" type="text" style="color:red;margin-left: 10px;"
            icon="el-icon-close" @click="handle(scope.row)">拒绝
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </div>
</template>

<script>
  import BasicsForm from "@/components/BasicsForm";
  import {
    approveDoctorChangeApply
  } from "@/api/manbing/hospital";
  import {
    doctorChangeApplyList
  } from "@/api/manbing/doctor";
  export default {
    name: "Sysmsg",
    components: {
      BasicsForm
    },
    data() {
      return {
        loading: false,
        tableLoading: false,
        total: 0,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        tableData: [],
        item: {},
      };
    },
    created() {
      this.getList();
    },
    methods: {
      //列表数据
      getList() {
        this.loading = true;
        this.tableLoading = true;
        doctorChangeApplyList(this.queryParams)
          .then((res) => {
            if (res.code == 200) {
              this.tableData = res.rows;
              this.total = res.total;
            }
          })
          .finally(() => {
            this.loading = false;
            this.tableLoading = false;
          });
      },
      handle(item) {
        this.$prompt('', '请输入拒绝理由', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
          inputErrorMessage: '请输入拒绝理由'
        }).then(({
          value
        }) => {
            this.submit(item,false,value)
        })
      },
      submit(item,flag,refuseReason){
        approveDoctorChangeApply({dcId:item.dcId,state:flag?1:2,refuseReason}).then(res=>{
          if (res.code == 200) {
            this.$modal.msgSuccess('审核完成');
            this.getList()
          }
        })
      }
    },
  };
</script>
<style scoped lang="scss">
</style>
